﻿@namespace SageKing.Studio.Pages.SageKingMessage.component

@implements IAddEdit<SysSageKingMessageAttribute,long>

@inject SysSageKingMessageAttributeService dataService
@inject SelectEnumCacheService<DataStreamTypeEnum> selectCacheService

<Form @ref="form"
      Model="@model"
      ValidateOnChange="true"
      Layout="@FormLayout.Horizontal"
      LabelColSpan="4" WrapperColSpan="20">

    <FormItem Label="属性名称">
        <Input ShowCount MaxLength="64" @bind-Value="@model.Name" />
    </FormItem>

    <FormItem Label="属性类型">
        <Select @bind-Value="@model.Type"
                DataSource="@SelectType"
                DefaultValue="DataStreamTypeEnum.String"
                LabelName="@nameof(KeyValue<string, DataStreamTypeEnum>.Key)"
                ValueName="@nameof(KeyValue<string, DataStreamTypeEnum>.Value)"
                Style="width: 100%;"
                TItemValue="DataStreamTypeEnum"
                TItem="KeyValue<string, DataStreamTypeEnum>"
                Placeholder="请选属性类型"
                DefaultActiveFirstOption="true"
                EnableSearch>
        </Select>
    </FormItem>
    <FormItem Label="是否启用">
        <Switch @bind-Value="@context.Status" CheckedChildren="开" UnCheckedChildren="关"></Switch>
    </FormItem>
    <FormItem Label="是否必填">
        <Switch @bind-Value="@context.Required" CheckedChildren="是" UnCheckedChildren="否"></Switch>
    </FormItem>
    <FormItem Label="显示名称">
        <Input ShowCount MaxLength="64" @bind-Value="@model.DisplayName" />
    </FormItem>
    <FormItem Label="描述信息">
        <TextArea ShowCount MaxLength="200" Width="100%" Placeholder="描述信息" @bind-Value="@context.Description"></TextArea>
    </FormItem>
</Form>
@code {

    #region IAddEdit
    public IAddEdit<SysSageKingMessageAttribute, long> Me { get { return this; } }

    public bool IsVersionValidation { get; set; } = true;

    [Parameter]
    public string Title { get; set; }

    [Parameter]
    public SysSageKingMessageAttribute model { get; set; }

    public IBaseService<SysSageKingMessageAttribute, long> DataService
    { get { return dataService; } }

    public AntDesign.Form<SysSageKingMessageAttribute> form { get; set; }
    #endregion

    //select data
    IList<KeyValue<string, DataStreamTypeEnum>> SelectType;

    public Action<SysSageKingMessageAttribute,ChangedEnum> OnModelChanged{ get; set; }

    protected override async Task OnInitializedAsync()
    {
        SelectType = selectCacheService.GetCache((int)DataStreamTypeEnum.String, (int)DataStreamTypeEnum.Float64, true);
    }

}
